﻿
#pragma once
#include <Windows.h>
#include <vector>
#include <list>
#include <set>
#include <map>

#pragma warning(disable:4018)	//有符号/无符号不匹配
#pragma warning(disable:4244)	//从float转换到int，可能丢失数据
#pragma warning(disable:4996)	//function or variable may be unsafe

//main.cpp
extern const int AppMajorVersion;
extern const int AppMinorVersion;
extern const int WinViewWidth;
extern const int WinViewHeight;
extern const int UpdateTime;
extern HWND hWndMain;

class GDirect2dManager;
class GResourceManager;
class GUIManager;
extern GDirect2dManager* D2dMgr;
extern GResourceManager* ResMgr;
extern GUIManager* UiMgr;


//utility.cpp
struct wstrless_t
{
	bool operator()(const WCHAR* a, const WCHAR* b) const
	{
		return wcscmp(a,b)<0;
	}
};

bool wstrless(WCHAR* s1,WCHAR* s2);
WCHAR* wstrdup(WCHAR* wstr);
void wstrfree(WCHAR* wstr);
BOOL wstreql(WCHAR* wstr1,WCHAR* wstr2);
BOOL fequal(float Value1,float Value2);
int Mul1000(float Value);
float fround(float Value,unsigned int NumDigits);
void FormatInt64WithChineseStyle(WCHAR* Buf,LONGLONG Value,BOOL ForceSign);

int GenerateId();
BOOL PointInRect(int X,int Y,int Left,int Top,int Width,int Height);
void SetImmBoxPosition(HWND hWnd,int X,int Y);
int GetImmResultString(HWND hWnd,WCHAR* ImmBuf,int BufLen);
void CopyTextToClipboard(HWND hWnd,WCHAR* Text,int Len);
void PasteTextFromClipboard(HWND hWnd,WCHAR* Buffer,int MaxBufLen);
int ParseIntText(WCHAR* Text,int Len=-1);
float ParseFloatText(WCHAR* Text,int Len=-1);	//只支持12位数字，支持百分号，允许省略整数部分的0


#define PC(v)	(v*0.01f)


//需要T实现operator<()
template<typename T>
void InsertSort(T* ObjArray,int Num)
{
	for (int i=0;i<Num;i++)
	{
		for (int j=0;j<i;j++)	//已排好序的不包括i
		{
			if (ObjArray[i]<ObjArray[j])
			{
				T Temp=ObjArray[i];
				memmove(ObjArray+j+1,ObjArray+j,(i-j)*sizeof(T));
				ObjArray[j]=Temp;
				break;
			}
		}
	}
}



